﻿using System;
using System.Web;
using System.Collections.Specialized;
using System.Reflection;

namespace CF.Web
{
    /// <summary>
    /// facade(HttpHandler)
    /// </summary>
   public class facade:IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            NameValueCollection ps = new NameValueCollection(context.Request.Params);
            //ps.Set("query", ps["query"] + "&gridsort=" + ps["sort"] + "&dir=" + ps["dir"]);

            //if (ps["s_method"] == "save" && !HttpContext.Current.User.Identity.IsAuthenticated)
            //{
            //    context.Response.Write("{\"success\": false,\"data\":\"" + "dose not login" + "\"}");
            //    context.Response.End();
            //}

            string action = context.Request["action"];
            Callback ops = new Callback();
            MethodInfo method = typeof(Callback).GetMethod(action);
            string msg = string.Empty;
            Object obj = method.Invoke(ops, new object[] { ps });
            msg = obj.ToString();

            //String cb = context.Request["callback"];
            //bool tag = cb != null;
            //context.Response.ContentType = tag ? "text/javascript" : "application/x-json";
            //if (tag) msg = cb + "(" + msg + ")";

            context.Response.Write(msg);
        }
        
        public bool IsReusable
        {
            get { return false; }
        }
    }
}
